package com.qf.manager.service.impl;


import com.qf.manager.mapper.ProductCustomMapper;
import com.qf.manager.mapper.ProductMapper;
import com.qf.manager.pojo.po.Product;
import com.qf.manager.pojo.po.ProductExample;
import com.qf.manager.service.Service;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@org.springframework.stereotype.Service
@Transactional
public class ServiceImpl implements Service {
    @Autowired
    ProductCustomMapper pcm;
    @Autowired
    ProductMapper  productMapper;
    @Override
    public List<Product> selectProduct(Long page, Long limit) {

        List<Product> products = pcm.selectProduct(page, limit);

        return products;
    }

    @Override
    public int selectCount() {


        return pcm.selectCount();
    }

    @Override
    public boolean delProduct(String pid) {
            int a=0;
        try {
            a = productMapper.deleteByPrimaryKey(pid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        boolean result=false;
        if(a!=0){

            result=true;
        }
        return result;
    }

    @Override
    public int editProduct(Product product) {


        int i = 0;
        try {
            i = productMapper.updateByPrimaryKeySelective(product);
        } catch (Exception e) {

            e.printStackTrace();
        }


        return i;
    }

    @Override
    public Product selectProductByPid(String pid) {

        Product product1 = productMapper.selectByPrimaryKey(pid);

        return product1;
    }

    @Override
    public int updateProduct(Product product) {

        int i = productMapper.updateByPrimaryKeySelective(product);
        return i;
    }
}
